//获取url的参数,判断类型
var Type = getUrlParam('type');

//日期格式化
var calendarDateFormat = myApp.calendar({
	input: '#_arrivaltime_',
    monthNames: ['01月', '02月', '03月', '04月', '05月', '06月', '07月', '08月' , '09月' , '10月', '11月', '12月'],
    dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
    closeOnSelect:true,
});   
var calendarDateFormat = myApp.calendar({
	input: '#receiptarrivalTime',
    monthNames: ['01月', '02月', '03月', '04月', '05月', '06月', '07月', '08月' , '09月' , '10月', '11月', '12月'],
    dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#_deliveryTime',
    monthNames: ['01月', '02月', '03月', '04月', '05月', '06月', '07月', '08月' , '09月' , '10月', '11月', '12月'],
    dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#paybackarrivalTime',
    monthNames: ['01月', '02月', '03月', '04月', '05月', '06月', '07月', '08月' , '09月' , '10月', '11月', '12月'],
    dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#carrivalTime',
    monthNames: ['01月', '02月', '03月', '04月', '05月', '06月', '07月', '08月' , '09月' , '10月', '11月', '12月'],
    dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#cusdarrivalTime',
    monthNames: ['01月', '02月', '03月', '04月', '05月', '06月', '07月', '08月' , '09月' , '10月', '11月', '12月'],
    dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
    closeOnSelect:true,
});

//顶部按钮固定
function chromahead() {
	var _top = $(".orderBar").offset().top;
	var _height = $(".orderBar").height();
	if(APP){           	
        $("#common_header").hide();
    	if($(".subnavbar").length>0){
    		var h=$(".subnavbar").height();
    	}else{
    		var h=0;
    	}           	
    	$("#app_no_header").css("padding-top",h);
    	$("#term_app_btn").hide();
    }else{
    	if($(".subnavbar").length>0){
    		if($(".subnavbar table").length>0){           			
    			var h=$(".subnavbar").height()+_top;
    		}else{
    			var h=$(".subnavbar").height()+_top;
    		}           		
    	}else{
    		var h=_top;
    	}     
    	$("#app_no_header").css("padding-top",h);
    	$(".navbar").css("top","0px");
    	$("#common_header").show();
    	$("#term_app_btn").show();
    }
}

$(function() {
	chromahead();
	//点击订单进入详情页
	$("#order_list").on("click",".product_list",function(){
		var id=$(this).attr("data-id");
		if(Type=="parcels"){
			var typeValue=2;
		}else if(Type=="rings"){
			var typeValue=3;
		}else if(Type=="gems"){
			var typeValue=4;
		}else if(Type=="emeralds"){
			var typeValue=5;
		}else if(Type=="golds"){
			var typeValue=6;
		}else if(Type == "inlaysettings"){
            var typeValue=7;
		}
		var link_url="/Team/OrderDetail?ID="+id+"&type="+typeValue;
		if(APP){
			var appJson={};
   			appJson.title=_("订单详情");
   			appJson.url=app_url+link_url;	
   			YiYi_APP.showNewPage(JSON.stringify(appJson));
		}else{
			location.href=link_url;
		}
	});

    //付款 充值金额大于0的
    $("#_chargingAmount").on("input",calMoney);

    //精准相加
    function addNum(num1,num2){
        var r1,r2,m,n;
        try{r1=num1.toString().split(".")[1].length}catch(e){r1=0}
        try{r2=num2.toString().split(".")[1].length}catch(e){r2=0}
        m = Math.pow(10,Math.max(r1,r2));
        n = (r1>=r2)?r1:r2;
        return ((num1*m + num2*m)/m).toFixed(n);
    }

    //点击收款事件
    $("#AddBill").click(function () {
        var _Balance = 0;
        var _USDBalance = 0;
        var _selected=$("#order .check_list_box span.selected");
        //用户数组start
        selnamelist = {};//用户数组
        pstalist = {};
        var rmbMoney=0;
        var usdMoney=0;
        for (var i = 0; i < _selected.length ; i++) {//得到所有选中的行
            var _skey = _selected.eq(i).parent().attr("lang");//得到当前选中的行的用户
            var pays = _selected.eq(i).parent().attr("data-PaymentStatus");//得到收款状态值

            var tempRmbMoney = Number(_selected.eq(i).parent().attr("data-first"));
            var tempUsdMoney = Number(_selected.eq(i).parent().attr("data-second"));
            var inventoryCount=_selected.eq(i).parent().attr("data-weight")  //购买重量

			if(Type=="parcels"){
				rmbMoney=addNum(rmbMoney,tempRmbMoney*inventoryCount)
				usdMoney=addNum(usdMoney,tempUsdMoney*inventoryCount);
			}else if(Type == "inlaysettings"){
                var rate=$.cookie("InlaySettingsRate");
                rmbMoney=addNum(rmbMoney,tempRmbMoney)
                usdMoney=rmbMoney/rate;
            }else{
                rmbMoney=addNum(rmbMoney,tempRmbMoney)
                usdMoney=addNum(usdMoney,tempUsdMoney);
			}

            var orderstatuss =_selected.eq(i).attr("data");//得到订单状态值
            selnamelist[_skey] = _skey;//用户数组
            pstalist[pays] = pays;//支付数组
			_Balance = Number(_selected.eq(i).parent().attr("data-Balance"));
            _USDBalance = Number(_selected.eq(i).parent().attr("data-USDBalance"));

        }
        var sleng = 0;//主要用来做首行判断
        var samename = true;//是否是同一用户
        var sfirst = 0;//第一个用户记录
        for (var ss in selnamelist) {
            if (sleng == 0)//用户记录
                sfirst = selnamelist[ss];
            else {
                if (selnamelist[ss] != sfirst) {//当前用户与首次不同
                    samename = false;
                    break;
                }
            }
            sleng++;
        }
        var pleng = 0;//主要用来做首行判断
        var psta = true;//是否是未收状态
        for (var pp in pstalist) {
            if (pstalist[pp] != 0) {//当前用户与首次不同
                psta = false;
                break;
            }
            pleng++;
        }
        if (samename) {
            if (psta) {
                //通过
				$("#_payCustID").html(sfirst);//CustomerID 12-14
				PayOrders_Js(orderstatuss,_Balance,_USDBalance,rmbMoney,usdMoney);//收款
                //PayOrders(sfirst);
            } else {
                if (orderstatuss == 7) {
                    PayOrders_Js(orderstatuss,_Balance,_USDBalance,rmbMoney,usdMoney);//收款

                } else {
                    myApp.alert(_("【收款】选择不当！请选择“未收”订单"));
                }
            }
        } else {
            //未通过-不同一客户
            if (orderstatuss == 7) {
                PayOrders_Js(orderstatuss,_Balance,_USDBalance,rmbMoney,usdMoney);//收款
            } else {
				myApp.alert("【收款】"+_("选择不当！请选择“同一客户”的订单"));
            }
        }
        //用户数组end
    });
	
	//点击付款事件
    $(".ReceiptOrders").click(function () {
        pstalist = {};
        var selected = $("#order .check_list_box span.selected");
        for (var i = 0; i < selected.size() ; i++) {//得到所有选中的行
            var _skey = selected.eq(i).parent().attr("lang");//得到当前选中的行
            var pays = selected.eq(i).parent().attr("data-receiptStatus");//得到付款状态值

            pstalist[pays] = pays;//支付数组
        }
//      var total_price = $(".check_first").html($(".product_list_price").html());
        var pleng = 0;//主要用来做首行判断
        var psta = true;//是否是未收状态
        for (var pp in pstalist) {
            if (pstalist[pp] == 1) {//当前用户与首次不同  1已付 0未收和2未清可以付款
                psta = false;
                break;
            }
            pleng++;
        }
        if (psta) {  //通过
            ReceiptOrders_Js();//付款
        } else {
        	var msg = _("【付款】选择不当！请选择'未收''未清'订单");
        	myApp.alert(msg);
        }        
    });
	
	//申请充值输入验证 12-10
	var validate = $("._balance").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		errorPlacement: function(error, element) {
			if(element.is(":radio"))
				error.appendTo(element.parent().parent());
			else if(element.is(":checkbox"))
				error.appendTo(element.parent().parent());
			else
				error.appendTo(element.parent().next());
		}, //调radio
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ApplyFlow(); //添加流水
		},
		rules: {
			RealName: "required", //为了解决由于网络问题导致客户信息无法加载完成却又已经提交了申请最后无法审核问题 2017-02-16
			Balance: "required",
			Amount: "required",
			Remarks: "required",
			Account: "required",
			ArrivalTime: "required",
		},
		messages: {
			RealName: "",
			Balance: "",
			Amount: "",
			Remarks: "",
			Account: "账户必选",
			ArrivalTime: "",
		}
	});

	//申请美金充值输入验证 12-10
	var validate = $("._usdbalance").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		errorPlacement: function(error, element) {
			if(element.is(":radio"))
				error.appendTo(element.parent().parent());
			else if(element.is(":checkbox"))
				error.appendTo(element.parent().parent());
			else
				error.appendTo(element.parent().next());
		}, //调radio
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ApplyUSDFlow(); //添加流水
		},
		rules: {
			RealName: "required", //为了解决由于网络问题导致客户信息无法加载完成却又已经提交了申请最后无法审核问题 2017-02-16
			Balance: "required",
			Amount: "required",
			Remarks: "required",
			Account: "required",
			ArrivalTime: "required",
		},
		messages: {
			RealName: "",
			Balance: "",
			Amount: "",
			Remarks: "",
			Account: _("账户必选"),
			ArrivalTime: "",
		}
	});

	//订单充值输入验证 class=_re
	var validate = $("._re").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			AddCharge(); //客户充值
		},
		rules: {
			AmountOfMoney: "required",
			Remarks: "required",
			PaymentModel: "required",
			AdddateTime: "required",
		},
		messages: {
			AmountOfMoney: "",
			Remarks: "",
			PaymentModel: "",
			AdddateTime: "",
		}
	});

	//作废订单输入验证 id=_cancel
	var validate = $("#_cancel").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			CancelOrders(); //订单作废
		},
		rules: {
			SalesRemarks: "required",
		},
		messages: {
			SalesRemarks: "",
		}
	});

	//自留订单输入验证 id=_stock
	var validate = $("#_stock").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			StockOrders(); //订单自留
		},
		rules: {
			SalesRemarks: "required",
		},
		messages: {
			SalesRemarks: "",
		}
	});

	//退回订单输入验证 id=_return
	var validate = $("#_return").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ReturnOrders(); //订单退回
		},
		rules: {
			SalesRemarks: "required",
		},
		messages: {
			SalesRemarks: ""
		}
	});

	//兑率订单输入验证 id=_exchange
	var validate = $("#_exchange").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ExchangeOrders(); //订单兑率
		},
		rules: {
			PurchaseExchangerate: "required",
		},
		messages: {
			PurchaseExchangerate: "",
		}
	});

	//订单转移输入验证 id=_transfer
	var validate = $("#_transfer").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ModifyPurchaseUserID(); //订单转移
		},
		rules: {
			PurchasesUserID: "required",
		},
		messages: {
			PurchasesUserID: "",
		}
	});

	//订单入库输入验证
	var validate = $("#_arrival").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ArrivalOrders(); //订单到货
		},
		rules: {
			Arrivaltime: "required",
		},
		messages: {
			Arrivaltime: "",
		}
	});

	//收款输入验证 id=_pay
	var validate = $("#_pay").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			PayOrders(); //收款
		},
		rules: {
			Currency: "required",
			ArrivalTime: "required",
			Remarks:"reuqired",
		},
		messages: {
			Currency: "",
			ArrivalTime: "",
			Remarks:"",
		}
	});

	//收款输入验证 id=_payback
	var validate = $("#_payback").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			PayBackOrders(); //收款
		},
		rules: {
			BankID: "required",
			PayBackAmount: "required",
			ArrivalTime: "required",
		},
		messages: {
			BankID: "",
			PayBackAmount: "",
			ArrivalTime: "",
		}
	});

	//付款输入验证 id=_receipt
	var validate = $("#_receipt").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ReceiptOrders(); //付款
		},
		rules: {
			BankID: "required",
			ArrivalTime: "required",
		},
		messages: {
			BankID: "",
			ArrivalTime: "",
		}
	});

	//出货订单输入验证 id=_ship
	var validate = $("#_ship").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			EditShip(); //订单作废
		},
		rules: {
			ShipRemarks: "required",
		},
		messages: {
			ShipRemarks: "",
		}
	});

	//批量改价输入验证 id= _revise           
	var validate = $("#_revise").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ReviseOrders(); //批量改价
		},
		rules: {
			SalesExchangerate: "required",
			DiscountReturn: "required",
			Discount: "required",
		},
		messages: {
			SalesExchangerate:"必填",
			DiscountReturn: "必填",
			Discount: "必填",
		}
	});

	//单个改价输入验证 id= _reviseOrder           
	var validate = $("#_reviseOrder").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ReviseAnOrder(); //单个改价
		},
		rules: {
			SalesExchangerate: "required",
			Confirmdiscount: "required",
			ConfirmPrice: "required",
		},
		messages: {
			SalesExchangerate: "必填",
			Confirmdiscount: "必填",
			ConfirmPrice: "必填",
		}
	});

	//修改运费输入验证          
	var validate = $("#_frei").validate({
		debug: true, //调试模式取消submit的默认提交功能   
		focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
		onkeyup: false,
		submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
			ModFreight(); //修改运费
		},
		rules: {
			Freight: {
				required: true
			},
		},
		messages: {
			Freight: {
				'required': ''
			}
		}
	});


    //采购  _buyPriceUSD  _buyPrice
    function calc5() {
        var rate = $("#_purchaseExchange").val() || 1;
        var price = $("#_buyPriceUSD").val(); //改变USD买价
        if(price) {
            $("#_buyPrice").val(formatRMBPrice(parseFloat(price * rate))); //RMB买价
        }
    }

    function calc6() {
        var rate = $("#_purchaseExchange").val() || 1;
        var price = $("#_buyPrice").val(); //改变RMB买价
        if(price) {
            $("#_buyPriceUSD").val(formatUSDPrice(parseFloat(price / rate))); //USD买价
        }
    }
    //价格写入，只需填一个，其他自动换算
    //修改售价
    $("#_buyPriceUSD,#_purchaseExchange").change(function() {
        calc5();
    }); ////USD买价,采购汇率
    $("#_buyPrice").change(function() {
        calc6();
    }); //RMB买价

});



//批量操作按钮显示和隐藏控制

//转移ModifyPurchaseUserID 优惠ReviseOrders 备注RemarkOrder 确认到货ArrivalOrders 取消到货CancelArrivalOrders 预制单AddShip 打单PrintShip 出货EditShip 收款AddBill 付款ReceiptOrders 作废CancelOrders 自留StockOrders 退回ReturnOrders 兑率ExchangeOrders 删除DelOrders 运费ModFreight 现货款PayStock
function check_checkbutton(lib) {
	var lis=lib;
	switch(lib) {
		// 1待采购 2待到货 3待出货 4已出货 5已作废 6 已自留 7已退回 
		case 1:
			lib = '.ModifyPurchaseUserID,.ReviseOrders,.RemarkOrder,.CancelOrders' //当订单状态为1时，RemarkOrder批量按钮亮 8-23
			break;
		case 2:
			lib = '.ModifyPurchaseUserID,.ReviseOrders,.ArrivalOrders,.RemarkOrder,.AddBill,.ReceiptOrders,.AddShip' //.ExchangeOrders,
			break;
		case 3:
			lib = '.ModifyPurchaseUserID,.ReviseOrders,.AddShip,.PrintShip,.EditShip,.AddBill,.ReceiptOrders,.RemarkOrder,.EditShip,.ExchangeOrders,.CancelArrivalOrders,.StockOrders,.ReturnOrders,.PayStock,.ModFreight'
			break;
		case 4:
			lib = '.ModifyPurchaseUserID,.ReviseOrders,.RemarkOrder,.PrintShip,.AddBill,.ReceiptOrders,.ExchangeOrders,.StockOrders,.ReturnOrders,.PayStock,.ModFreight' //运费11-11  只有已出货4才可以支付(收款 或 申请支付)
			break;
		case 5:
			lib = '.DelOrders,.RemarkOrder' //删除 9-29
			break;
		case 6:
			lib = '.ModifyPurchaseUserID,.ReviseOrders,.RemarkOrder'
			break;
		case 7:
			lib = '.RemarkOrder'
			break;
		case 34:
			lib = '.ReceiptOrders,.AddBill,.ModFreight' //待出货 已出货 两个订单状态时 付款 和 收款 、预制单、运费 亮
			break;
		default:
			break;
	}
	if($("#order .check_list_box span.selected").size() != 0) {
		$(lib).css("background-color", primary_color);
		$(lib).attr("disabled", false);
	} else {
		clearAll();
	}
    btnCancelOrders(lis);
}

//管理員在待到货下也可操作作废按钮
function btnCancelOrders(lib){
    if(RoleID==1 && lib == 2){
        $(".CancelOrders").css("background-color", primary_color);
        $(".CancelOrders").attr("disabled", false);
    }
}

//选中判断按钮操作
function handleBtn(){
	var self =this;
	 datalist = {};
        for (var i = 0; i < $("#order .check_list_box span.selected").size() ; i++) {  //得到所有选中的行
            var _key = $("#order .check_list_box span.selected").eq(i).attr("data");   //得到当前选中的行  data='"+_result[i].OrderStatus+"'
            datalist[_key] = _key;
        }
        
        var lengths = 0;  //主要用来做首行判断
        var tempdata = true; //是否只有一种类别
        var first = 0;     //第一种类别记录
        for (var d in datalist) {
            if (lengths == 0) //记录第一次类别
                first = datalist[d];
            else {
                if (datalist[d] != first) //记录当前类别与首次不同
                {
                    tempdata = false;
                    break;
                }
            }
            lengths++; //记录增加1
        }
        if (tempdata) //全部类别一样
        {
            if (first != 0) { //并且记录到类别（选中了一个或以上）
                eval("check_checkbutton(" + first + ")");
            }else if (curstate != 0) {   //不是全选择（指待采购  待到货  待出货  已出货  已作废） order.cshtml里面有调用这个参数做类别记录
                eval("check_checkbutton(" + curstate + ")");  //调用对应的，主要用于取消全选时去掉对应的高亮按钮
            }else{ //全部类别（不做处理先）
            }
        } else {
            self.clearAll();
        }
        	
}

function clearAll() {
	$(".search_btn_b").attr("disabled", true);
	$(".search_btn_b").css("background-color", "#a1a1a1");
}
function searClearAll() {
	$(".search_btn_b").attr("disabled", true);
	$(".search_btn_b").css("background-color", "#a1a1a1");
	$("#order .check_list_box span").removeClass("selected");
}




//打印出货单 9-20
function PrintShip() {

	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}
	var Url = "";
	if(Type=="parcels"){
		Url = "/Team/ParcelPrintShipOrders";
	}else if(Type=="rings"){
		Url = "/Team/RingPrintShipOrders";
	}else if(Type=="gems"){
		Url = "/Team/GemPrintShipOrders";
	}else if(Type=="emeralds"){
		Url = "/Team/EmeraldPrintShipOrders";
	} else if(Type=="golds"){
		Url = "/Team/PrimeGoldsPrintShipOrders";
	}
	
	$.ajax({
		url: url, //提交地址
		type: "POST", //提交方式
		data: "{'OrderIDs':'" + _orderIDs + "'}",
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象

			if(_result.msgcode == true) {
				window.open(_result.msginfo); //打开文件
				myApp.alert(_("订单下载成功.如未自动下载，请查看文件是否被浏览器拦截。"));
			} else {
				myApp.alert(_result.msginfo);
			}

		}
	});
}
//订单备注
function RemarkOrder_Js(){
	myApp.popup(".RemarkOrder_box");
}
//备注订单
function RemarkOrder() {
	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}

	$.ajax({
		url: "/Team/ModifyRemarksOrdersNew",
		type: "POST", 
		data: "{'OrderIDs':'" + _orderIDs + "','Remarks':'" + $("#_remarks").val() + "','SalesRemarks':'" + $("#_salesRemarks").val() + "','PurchaseRemarks':'" + $("#_purchaseRemarks").val() + "','GoodsRemark':'" + $("#_goodsRemark").val() + "'}",
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')');
			if(_result["msgcode"] == true) {
				myApp.alert(_result["msginfo"],function(){
					myApp.closeModal(".RemarkOrder_box");
					$('.order-choose-detail span b').html(0);
					$("#checkbox_check_all").removeClass("selected"); //清除全选
					OrderSearch(); //加载订单
				});				
			} else {
				myApp.alert(_("备注订单")+":" + _result["msginfo"]);
			}
		}
	});
}


//作废订单
function CancelOrders() {
	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}

	$.ajax({
		url: "/Team/CancelOrdersNew", //提交地址
		type: "POST", //提交方式
		data: "{'OrderIDs':'" + _orderIDs + "','SalesRemarks':'" + $("#_cancelRemarks").val() + "'}",
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象
			myApp.alert(_result["msginfo"],function(){
				myApp.closeModal(".CancelOrders_box");
                $("#check-total-price").html(0);
				OrderSearch(); //搜索订单8-28 
			});			
		}
	});
}

//自留变现
function StockOrders_Js(){
    //用户数组start
	    selnamelist = {};//用户数组
	    for (var i = 0; i < $("#stock_body .check_list_box span.selected").size() ; i++) {//得到所有选中的行
	        var _skey = $("#stock_body .check_list_box span.selected").eq(i).parent().attr("lang");//得到当前选中的行
	        selnamelist[_skey] = _skey;//用户数组
	    }
	    var sleng = 0;//主要用来做首行判断
	    var samename = true;//是否是同一用户
	    var sfirst = 0;//第一个用户记录
	    for (var ss in selnamelist) {
	        if (sleng == 0)//用户记录
	            sfirst = selnamelist[ss];
	        else {
	            if (selnamelist[ss] != sfirst) {//当前用户与首次不同
	                samename = false;
	                break;
	            }
	        }
	        sleng++;
	    }
	    if (samename) {
	        //通过
	        $("#_stockCustomerID").html(sfirst);//CustomerID 12-28
	        myApp.popup(".StockOrders_box");
	    } else {
	        myApp.alert(_("【自留变货】选择不当！请选择“同一客户”的订单"));
	    }
	    //用户数组end
}

//自留订单
function StockOrders() {
	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _customerID = orderlistCb.parent().attr("data-customerID");
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}	
	var submitJson={};
	submitJson.OrderIDs=_orderIDs;
	submitJson.SalesRemarks=$("#_stockRemarks").val();
	submitJson.SalesUserID=UserID;
	submitJson.CustomerID=_customerID;
	$.ajax({
		url: "/Team/ModifyOnlineOrderNew",
		type: "POST", 
		data: JSON.stringify(submitJson),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')');
			myApp.alert(_result["msginfo"],function(){
				myApp.closeModal(".StockOrders_box");
                $("#check-total-price").html(0);
				OrderSearch();
			});			
		}
	});
}

//退回供应商
function ReturnOrders_Js(){
   
    //点击退回事件 12-28
    //用户数组start
    selnamelist = {};//用户数组
    for (var i = 0; i < $("#stock_body .check_list_box span.selected").size() ; i++) {//得到所有选中的行
        var _skey = $("#stock_body .check_list_box span.selected").eq(i).parent().attr("lang");//得到当前选中的行
        selnamelist[_skey] = _skey;//用户数组
    }
    var sleng = 0;//主要用来做首行判断
    var samename = true;//是否是同一用户
    var sfirst = 0;//第一个用户记录
    for (var ss in selnamelist) {
        if (sleng == 0)//用户记录
            sfirst = selnamelist[ss];
        else {
            if (selnamelist[ss] != sfirst) {//当前用户与首次不同
                samename = false;
                break;
            }
        }
        sleng++;
    }
    if (samename) {
        //通过
        $("#_returnCustomerID").html(sfirst);//CustomerID 12-28
        myApp.popup(".ReturnOrders_box");
    } else {
        myApp.alert(_("【退回供应商】选择不当！请选择“同一客户”的订单"));
    }
    //用户数组end
    
}

//退回订单
function ReturnOrders() {
	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}
	

	var submitJson={};
	submitJson.OrderIDs=_orderIDs;
	submitJson.SalesRemarks=$("#_returnRemarks").val();
	submitJson.SalesUserID=customerId;
	submitJson.CustomerID=$("#_returnCustomerID").text();
	$.ajax({
		url: "/Team/ReturnOrdersNew",
		type: "POST", 
		data: JSON.stringify(submitJson), //_returnRemarks退回
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); 
			myApp.alert(_result["msginfo"],function(){
				myApp.closeModal(".ReturnOrders_box");
				$("#checkbox_check_all").removeClass("selected"); //清除全选
				$('.order-choose-detail span b').html(0);
				OrderSearch(); //搜索订单8-28 
			});
			
		}
	});
}

//订单转移
function ModifyPurchaseUserID() {
	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}
	
	$.ajax({
		url: "/Team/ModifyPurchaseUser",
		type: "POST", 
		data: "{'OrderIDs':'" + _orderIDs + "','PurchaseUserID':'" + $("#_purchasesUserIDs").val() + "'}", //$("#test option:selected")
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); 
			myApp.alert(_(_result.msginfo),function(){
				myApp.closeModal(".ModifyPurchaseUserID_box");
				OrderSearch(); //搜索订单8-28
				$('.order-choose-detail span b').html(0);
				$("#checkbox_check_all").removeClass("selected"); //清除全选
			});
			
		}
	});
}

//订单转移框
function ModifyPurchaseUserID_Js() {
	myApp.popup(".ModifyPurchaseUserID_box");
	//纯采购列表 9-26
	$.ajax({
		url: "/Team/GetPurchaseList", 
		type: "POST", 
		//data: "{'PageSize':'" + 100 + "','PageIndex':'" + 1 + "'}",
		data: "{'SysStatus':'" + 1 + "'}",
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象

			var options = "";
			options += '<option value="">'+_("采购")+'</option>';

			if(_result.msgcode == false) {

				options += '<option value=""  >' + _(_result.msginfo) + '</option>';
				$("#_purchaseUserIDs").html("");
				$("#_purchaseUserIDs").html(options);

			} else {

				for(var i = 0; i < _result.length; i++) {
					options += '<option value="' + _result[i].UserID + '"  >' + _result[i].RealName + '</option>';
				}
				$("#_purchasesUserIDs").html();
				$("#_purchasesUserIDs").html(options);
			}
		}
	});
}

//订单到货（批量或单个）
function ArrivalOrders() {
	//仅管理员1和物流员5

	myApp.confirm(_("【确认到货】确定要“确认到货”吗？"),function() {

		//OrderIDs值组装 _orderIDs="232,324"
		var orderlistCb = $("#order .check_list_box span.selected"); //checked的
		var _orderIDs = "";
		for(var i = 0; i < orderlistCb.length; i++) {
			if(i == 0)
				_orderIDs += orderlistCb[i].lang;
			else
				_orderIDs += "," + orderlistCb[i].lang;
		}

		$.ajax({
			url: "/Team/SubmitArrivalOrdersNew", //提交地址
			type: "POST", //提交方式
			data: "{'OrderIDs':'" + _orderIDs + "','ArrivalTime':'" + $("#_arrivaltime_").val() + "','ApplyID':'" + customerId + "'}",
			contentType: "application/json; charset=utf-8",
			success: function(result) {
				var _result = eval('(' + result + ')'); //eval()解析单个json对象
				if(_result.msgcode == true) {
					$(".ArrivalOrders_box input[type=reset]").trigger("click"); //清空form数据
					myApp.alert(_result["msginfo"],function(){
						myApp.closeModal(".ArrivalOrders_box");
						OrderSearch(); //搜索订单8-28
						$('#check-total-price').text(0)
					});					
				} else {
					myApp.alert(_result.msginfo);
				}
			}
		});
	});
}

//订单入库(定货到货)框
function ArrivalOrders_Js() {
	//仅管理员1和物流员5
	if(RoleID == 1 || RoleID == 5 || RoleID ==6) {
		myApp.popup(".ArrivalOrders_box");
	} else {
		myApp.alert(_("【确认到货】禁用"));
	}
}

//订单入库(定货到货)框
function CancelArrivalOrders_Js() {
	//仅管理员1和物流员5
	if(RoleID == 1 || RoleID == 5 ) {

		myApp.confirm(_("【取消到货】确定要“取消到货”吗？"),function() {

			var requestCancel = {};

			//OrderIDs值组装 _orderIDs="232,324"
			var orderlistCb = $("#order .check_list_box span.selected"); //checked的
			var _orderIDs = "";
			for(var i = 0; i < orderlistCb.length; i++) {
				if(i == 0)
					_orderIDs += orderlistCb[i].lang;
				else
					_orderIDs += "," + orderlistCb[i].lang;
			}

			requestCancel.OrderIDs = _orderIDs;
			requestCancel.ApplyID = customerId;
			

			$.ajax({
				url: "/Team/CancelArrivalOrdersNew", //提交地址
				type: "POST", //提交方式
				data: JSON.stringify(requestCancel),
				contentType: "application/json; charset=utf-8",
				success: function(result) {
					var _result = eval('(' + result + ')'); //eval()解析单个json对象

					if(_result.msgcode == true) {
						myApp.alert(_(_result.msginfo));
						$("#checkbox_check_all").removeClass("selected"); //清除全选
						$('.order-choose-detail span b').html(0);
						OrderSearch();
					} else {
						myApp.alert(_(_result.msginfo));
					}
				}
			});
		});

	} else {
		myApp.alert(_("【取消到货】禁用"));
	}
}

//修改采购汇率
function ExchangeOrders() {

	$(".all_loading_pic_box").show(); //加载中,请稍后...

	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}

	var requestExchange = {};

	requestExchange.OrderIDs = _orderIDs;
	requestExchange.PurchaseExchangerate = $("#_purchaseRate option:checked").val(); //_purchaseRate下拉框
	
	var Url;
	if(Type=="parcels"){
		Url = "/Team/ParcelExchangeOrders";
	}else if(Type=="rings"){
		Url = "/Team/RingExchangeOrders";
	}else if(Type=="gems"){
		Url = "/Team/GemExchangeOrders";
	}else if(Type=="emeralds"){
		Url = "/Team/EmeraldExchangeOrders";
	}else if(Type=="golds"){
		Url = "/Team/PrimeGoldsExchangeOrders";
	}
	
	$.ajax({
		url: Url,
		type: "POST", 
		data: JSON.stringify(requestExchange),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); 
			myApp.alert(_("成功")+"："+_result['succ']+"，"+_("失败")+"："+_result['fail'],function(){
				myApp.closeModal(".ExchangeOrders_box");
				OrderSearch();
			});
			
		}
	});
}

//付款
function ReceiptOrders() {

	//管理1和会计2

		myApp.confirm(_("确定各项参数无误,'付款'吗？"),function() {

			//OrderIDs值组装 _orderIDs="232,324"
			var orderlistCb = $("#order .check_list_box span.selected"); //checked的
			var _orderIDs = "";
			for(var i = 0; i < orderlistCb.length; i++) {
				if(i == 0)
					_orderIDs += orderlistCb[i].lang;
				else
					_orderIDs += "," + orderlistCb[i].lang;
			}
			

            var submitJson={};
            submitJson.OrderIDs=_orderIDs;
            submitJson.BankID=$("#_receiptBankID").val();
            submitJson.ReceiptAmount=$("#_receiptAmount").val();
            submitJson.ArrivalTime=$("#receiptarrivalTime").val();
            submitJson.UserID=UserID;

			$.ajax({
				url: "/Team/PayOrdersNew",
				type: "POST",
				data: JSON.stringify(submitJson),
				contentType: "application/json; charset=utf-8",
				success: function(result) {
					var _result = eval('(' + result + ')'); 

					if(_result.msgcode == true) {
						$(".ReceiptOrders_box input[type=reset]").trigger("click"); //清空form
						myApp.alert(_result.msginfo,function(){
							myApp.closeModal(".ReceiptOrders_box");
							OrderSearch();
							$("#checkbox_check_all").removeClass("selected"); //清除全选
							$('.order-choose-detail span b').html(0);

						});						
					} else {
						myApp.alert(_result.msginfo);
					}
				}
			});
		});


}

//小数相减的精确值计算
function accSub(arg1,arg2){
    var r1,r2,m,n;
    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
    m=Math.pow(10,Math.max(r1,r2));
    //last modify by deeka
    //动态控制精度长度
    n=(r1>=r2)?r1:r2;
    return ((arg1*m-arg2*m)/m).toFixed(n);
}
//解决0.01为0.1
function keepOneDecimalFull(num) {
    var result = parseFloat(num);
    if(Type!="inlaysettings"){
        if (isNaN(result)) {
            alert('传递参数错误，请检查！');
            return false;
        }
	}

    result = Math.ceil(num * 10) / 10;
    var s_x = result.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 1) {
        s_x += '0';
    }
    return s_x;
}


//收款账户
function PayOrders_Js(orderStatusValue,_Balance,_USDBalance,rmbMoney,usdMoney){
    $("#_pay :input").not("input[type=submit]").removeClass("error");
    if (orderStatusValue == 7) {
        if (RoleID == 1 || RoleID == 2 || RoleID==6) {
            myApp.popup("#PayBackOrders_box");//退回供应商回款  7 已退回
            var requestJson={};
            requestJson.Status=1;
            requestJson.CheckResult=1;
            if(CurrentRMB==true && CurrentUSD==false){
                requestJson.Currency=1;//人民币账户
            }else if(CurrentRMB==false && CurrentUSD==true){
                requestJson.Currency=2;//人民币账户
            }
            //收款账户
            $.ajax({
                url: "/Team/GetBankList",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestJson),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象

                    var options = "";
                    options += '<option value="">'+_("选择账户")+'</option>';
                    for (var i = 0; i < _result.length; i++) {
                        options += '<option value="' + _result[i].BankID + '"  >【' + _result[i].BankName + '】' + CurrencyFormat(_result[i].Currency) + '</option>';
                    }
                    $("#_paybackBankID").html(options);
                }
            });
        } else {
            alertMsgBox(_("【收款】禁用"));
        }

    } else {
        $(".check_first").html(formatRMBPrice(rmbMoney));
        $(".check_second").html(formatUSDPrice(usdMoney));
        GetBankList();
        $("#_currency option").remove();
        var $option = '<option value="" selected="selected">'+_("余额")+'</option>';
        if(CurrentRMB==true){
            $option+='<option value="1" class="CurrentRMB">￥:'+_Balance+'</option>';
        }
        if(CurrentUSD==true){
            $option +='<option value="2" class="CurrentUSD">$:'+_USDBalance+'</option>';
        }
        $("#_currency").html($option);

        //充入金额
        var addBalance=accSub(rmbMoney,_Balance);
        var addusdBalance=accSub(usdMoney,_USDBalance);
        addBalance=keepOneDecimalFull(addBalance);
        addusdBalance=keepOneDecimalFull(addusdBalance);
        $("#_currency").change(function(){
            if($(this).val() == 1&&$(this).val() != ''){
                if(rmbMoney>_Balance){
                    $("#_chargingAmount").val(Math.ceil(addBalance));
                    $("#_optionBank").addClass("error");

                    $("#remarks_inp").show(); //备注
                    $("#arrivalTime_inp").show(); //到账日期
                    $("#_remarks2").addClass("error");
                    $("#_remarks2").prop("required",true);
                    $("#_remarks2").val('');
                }else{
                    $("#_chargingAmount").val('');
                    $("#_optionBank").removeClass("error");
                    $("#_optionBank").prop("required",false);

                    $("#remarks_inp").hide();
                    $("#arrivalTime_inp").hide();
                    $("#_remarks2").removeClass("error");
                    $("#_remarks2").prop("required",false);
                }
            }else if($(this).val() == 2&&$(this).val() != ''){
                if(usdMoney>_USDBalance){
                    $("#_chargingAmount").val(addusdBalance);
                    $("#_optionBank").addClass("error");

                    $("#remarks_inp").show();
                    $("#arrivalTime_inp").show();
                    $("#_remarks2").addClass("error");
                    $("#_remarks2").prop("required",true);
                    $("#_remarks2").val('');
                }else{
                    $("#_chargingAmount").val('');
                    $("#_optionBank").removeClass("error");
                    $("#_optionBank").prop("required",false);

                    $("#remarks_inp").hide();
                    $("#arrivalTime_inp").hide();
                    $("#_remarks2").removeClass("error");
                    $("#_remarks2").prop("required",false);
                }
            }else{
                $("#_chargingAmount").val('');
            }
        })


		currentShow();
		myApp.popup("#PayOrders_box");//收客户款
        $('#arrivalTime_inp').hide();
        $('#remarks_inp').hide();

    }
}
function GetBankList(){
    $("#_optionBank option").remove();
    var requestAccount = {};

    requestAccount.Status = 1; //启用1
    requestAccount.Type = '2,3'; //01-11 只要传了Type就不显示Type=2和3的账户 01-11
    if(CurrentRMB==true && CurrentUSD==false){
        requestAccount.Currency = 1; //人民币1 美金2
    }else if(CurrentRMB==false && CurrentUSD==true){
        requestAccount.Currency = 2; //人民币1 美金2
    }
    $.ajax({
        url: "/Team/GetBankList", //提交地址
        type: "POST", //提交方式
        async: false, //异步 9-27
        data: JSON.stringify(requestAccount),
        contentType: "application/json; charset=utf-8",
        success: function(result) {
            var _result = eval('(' + result + ')'); //eval()解析单个json对象

            if(_result.msgcode == false) {
                var options = "";
                options += '<lable>' + _result.msginfo + '</label>';
                $("#_optionBank").html(options);
            } else {
                options += '<option value="">'+_("选择账户")+'</option>';
                for (var i = 0; i < _result.length; i++) {
                    options += '<option value="' + _result[i].BankID + '"  >' + _(_result[i].BankName) + '</option>';
                }
                $("#_optionBank").html(options);
            }
        }
    });
}
//收款
function PayOrders() {

	myApp.confirm(_("【收款】确定要使用'") + CurrencyFormat($("#_currency").val()) + _("余额支付吗？"),function(){

		//OrderIDs值组装 _orderIDs="232,324"
		var orderlistCb = $("#order .check_list_box span.selected"); //checked的
		var obj = {};
		obj.Amount = $("#_chargingAmount").val(); //充值金额
		obj.ArrivalTime = $("#_accountTime").val(); //到款日期
		obj.Account = $("#_optionBank").val(); //收款银行
		obj.CustomerID = $("#_payCustID").html();
		obj.Currency = $("#_currency").val();//币种
		obj.Remarks= $("#_remarks2").val(); //备注
		obj.UserID=UserID;
		obj.ReviewID=UserID;
		var _orderIDs = "";
		for(var i = 0; i < orderlistCb.length; i++) {
			if(i == 0)
				_orderIDs += orderlistCb[i].lang;
			else
				_orderIDs += "," + orderlistCb[i].lang;
		}
		obj.OrderIDs=_orderIDs

		$.ajax({
			url: "/Team/ReceiptOrdersNew",
			type: "POST", 
			data: JSON.stringify(obj),
			contentType: "application/json; charset=utf-8",
			success: function(result) {
				var _result = eval('(' + result + ')');

				if(_result.msgcode == true) {
					myApp.alert(_(_result.msginfo),function(){
						myApp.closeModal(".PayOrders_box");
						$("#check-total-price").html(0);
						OrderSearch(); //搜索订单8-28 
					});					
				} else {
					myApp.alert(_(_result.msginfo));
				}
			}
		});
	});
}

//收款
function PayBackOrders() {

	myApp.confirm(_("【收款】确定要'收款'吗？"),function() {

		//OrderIDs值组装 _orderIDs="232,324"
		var orderlistCb = $("#order .check_list_box span.selected"); //checked的
		var _orderIDs = "";
		for(var i = 0; i < orderlistCb.length; i++) {
			if(i == 0)
				_orderIDs += orderlistCb[i].lang;
			else
				_orderIDs += "," + orderlistCb[i].lang;
		}
	
		var Url;
		if(Type=="parcels"){
			Url = "/Team/ParcelBackOrders";
		}else if(Type=="rings"){
			Url = "/Team/PayBackOrders";
		}else if(Type=="gems"){
			Url = "/Team/GemBackOrders";
		}else if(Type=="emeralds"){
			Url = "/Team/EmeraldBackOrders";
		}else if(Type=="golds"){
			Url = "/Team/PrimeGoldsBackOrders";
		}
	
		$.ajax({
			url: Url,
			type: "POST",
			data: "{'OrderIDs':'" + _orderIDs + "','BankID':'" + $("#_paybackBankID").val() + "','ArrivalTime':'" + $("#paybackarrivalTime").val() + "','PayBackAmount':'" + $("#_paybackAmount").val() + "','ApplyID':'" + customerId + "'}",
			contentType: "application/json; charset=utf-8",
			success: function(result) {
				var _result = eval('(' + result + ')'); 

				if(_result.msgcode == true) {
					myApp.alert(_(_result.msginfo),function(){
						myApp.closeModal(".PayBackOrders_box");
						OrderSearch();
					});					
				} else {
					myApp.alert(_result.msginfo);
				}
			}
		});
	});
}

//订单删除
function DelOrders() {

	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}
	

	$.ajax({
		url: "/Team/DelOrdersNew",
		type: "POST", 
		data: "{'OrderIDs':'" + _orderIDs + "'}",
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')');
			if(_result["msgcode"] == false) {
				myApp.alert(_(_result["msginfo"]),function(){
					myApp.closeModal(".DelOrders_box");
					OrderSearch(); //搜索订单8-28 
				});
				
			} else {
				myApp.alert(_(_result["msginfo"]));
				myApp.closeModal(".DelOrders_box");
				OrderSearch(); 
			}			
		}
	});
}

//批量改价
function ReviseOrders_Js() {
	myApp.popup(".ReviseOrders_box");	
	var Rate = "";
		if(Type=="parcels"){
			Rate = "2";
		}else if(Type=="rings"){
			Rate = "3";
		}else if(Type=="gems"){
			Rate = "4";
		}else if(Type=="emeralds"){
			Rate = "5";
		}else if(Type=="golds"){
			Rate = "6";
		}else if(Type == "inlaysettings"){
            Rate = "7";
		}

	//获取销售汇率
	$.ajax({
		url: "/Team/GetRate", 
		type: "POST",
		//data: "",
		data: "{'SysSettingID':'" + Rate + "'}", //1裸钻
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象
			$("#_salesExchangerate").val(_result["data"].Rate);
		}
	});
}
//批量优惠
function ReviseOrders() {
	var order = {};
	//模式 mode 1 （批量加点） 和 0  (批量折扣)

	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}
	order.OrderIDs = _orderIDs;
	order.SalesExchangerate = $("#_salesExchangerate").val();
	order.Rebate = $("#_rebate").val();
	order.Discount = $("#_discount").val();

	$.ajax({
		url:"/Team/ReviseOrdersNew",
		type: "POST", 
		data:JSON.stringify(order),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象
			if(_result["msgcode"] == false) {
				myApp.alert(_(_result["msginfo"]),function(){
					myApp.closeModal(".ReviseOrders_box");
					OrderSearch(); //搜索订单8-28
				});
				
			} else {
				myApp.alert(_(_result["msginfo"]));
				myApp.closeModal(".ReviseOrders_box");
				$('.order-choose-detail span b').html(0);
				$("#checkbox_check_all").removeClass("selected"); //清除全选
				OrderSearch(); 
			}		
		}
	});
}

//单个改价
function ReviseAnOrder() {

	var reviseOrder = {};
	reviseOrder.OrderIDs = $("#_anorderid").val();
	// reviseOrder.Mode = $('input:radio[name="model"]:checked').val();
	reviseOrder.Mode = "1";
	if(Type == "inlaysettings"){
        reviseOrder.Material=$("#form_material").val();
        reviseOrder.CustomerGoldPrice=$("#g_price").val();
        reviseOrder.TotalWeight=$("#g_TotalWeight").val(); //总重
        reviseOrder.NetGoldWeight=$("#g_NetGoldWeight").val();
        reviseOrder.CustomerWastage=$("#g_Wastage").val();
        reviseOrder.CustomerSidePrice=$("#g_SidePrice").val();
        reviseOrder.CustomerLaborFee=$("#g_LaborFee").val();
        reviseOrder.CustomerInsurance=$("#g_Insurance").val();
        reviseOrder.CustomerSideLaborFee=$("#g_SideLaborFee").val();
        reviseOrder.SideNum=$("#g_SideNum").val();
        reviseOrder.ConfirmRMB=$("#_confirmPrice").val(); //人民币
	}else{
        reviseOrder.SalesExchangerate = $("#_salesRate").val();
        reviseOrder.ConfirmRMB = $("#_confirmPrice").val(); //人民币总价格
        reviseOrder.ConfirmUSD = $("#_BEFPrice").val(); //美元总价格
	}


	$.ajax({
		url: "/Team/ModifyConfirmPriceOrdersNew",
		type: "POST", 
		data: JSON.stringify(reviseOrder),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象

			if(_result["msgcode"] == false) {
				myApp.alert(_(_result["msginfo"]),function(){
					myApp.closeModal(".ReviseAnOrder_box");
					OrderSearch(); //加载订单列表
				});				
			} else {
				myApp.alert(_(_result["msginfo"]));
				myApp.closeModal(".ReviseAnOrder_box");
				$("#checkbox_check_all").removeClass("selected"); //清除全选
				$('.order-choose-detail span b').html(0);
				OrderSearch(); //加载订单列表
			}
		}
	});
}

//录入订单弹出框
function add_box() {
	myApp.popup(".add_pop_box");

	$.ajax({
		url: "/Team/GetCustomers", //提交地址
		type: "POST", //提交方式
		data: "{'SalesUserID':'" + customerId + "','UserID':'"+UserID+"'}", //,'PageSize':'" + 100 + "','PageIndex':'" + 1 + "'
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); 

			if(_result.msgcode == true) {
				var options = "";
				for(var i = 0; i < _result.Data.length; i++) {
					options += '<option value="' + _result.Data[i].CustomerID + '"  >' + _result.Data[i].RealName + '</option>';
				}
				$("#_customerID_").html("");
				$("#_customerID_").html(options);
			}
		}
	});
}

//修改兑率订单 9-2
function ExchangeOrders_Jsxx() {

	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}

	myApp.popup(".ExchangeOrders_box");
		var Url;
		if(Type=="parcels"){
			Url = "/Team/ParcelExchangeOrders";
		}else if(Type=="rings"){
			Url = "/Team/RingExchangeOrders";
		}else if(Type=="gems"){
			Url = "/Team/GemExchangeOrders";
		}else if(Type=="emeralds"){
			Url = "/Team/EmeraldExchangeOrders";
		}else if(Type=="golds"){
			Url = "/Team/PrimeGoldsExchangeOrders";
		}

	//周采购汇率
	$.ajax({
		url: Url,
		type: "POST", 
		data: "{'OrderIDs':'" + _orderIDs + "','PurchaseExchangerate':'" + $("#PurchaseExchangerate").val() + "'}", //周数(3+1)
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')');                   

			var options = "";
			options += '<option value="">'+_("最近4周采购汇率")+'</option>';
			for(var i = 0; i < _result.length; i++) {
				options += '<option value="' + _result[i].WeekPurchaseExchange + '"  >【' + _result[i].WeekPurchaseExchange.toFixed(5) + '】' + _result[i].SArrivalTime + ' - ' + _result[i].EArrivalTime + '</option>';
			}
			$("#_purchaseRate").html("");
			$("#_purchaseRate").html(options);
		}
	});
}

//修改兑率订单 9-2
function ExchangeOrders_Js() {

	$(".ExchangeOrders_box").show();

	$(".pop .colse_popbox").click(function() {
		$(".ExchangeOrders_box").hide();
	});

	//周采购汇率
	$.ajax({
		url: "/Team/OrderReport", //提交地址
		type: "POST", //提交方式
		data: "{'PageSize':'" + 3 + "'}", //周数(3+1)
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象                        

			var options = "";
			options += '<option value="">'+_("最近4周采购汇率")+'</option>';
			for(var i = 0; i < _result.length; i++) {
				options += '<option value="' + _result[i].WeekPurchaseExchange + '"  >【' + _result[i].WeekPurchaseExchange.toFixed(5) + '】' + _result[i].SArrivalTime + ' - ' + _result[i].EArrivalTime + '</option>';
			}
			$("#_purchaseRate").html("");
			$("#_purchaseRate").html(options);
		}
	});
}

//修改运费
function ModFreight_Js() {
   myApp.popup(".ModFreight_box");
}
//修改运费
function ModFreight() {
	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}
	
	$.ajax({
		url: "/Team/ModifyFreightOrdersNew",
		type: "POST",
		data: "{'OrderIDs':'" + _orderIDs + "','Freight':'" + $("#_freight").val() + "'}",
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')');

			if(_result.msgcode == true) {				
				myApp.alert(_(_result.msginfo),function(){
					$(".ModFreight_box input[type=reset]").trigger("click"); //清空form数据 11-11 关键 一定要放最前面
					myApp.closeModal(".ModFreight_box");
					$('.order-choose-detail span b').html(0);
					$("#checkbox_check_all").removeClass("selected"); //清除全选
					OrderSearch();
				});
				
			} else {
				myApp.alert(_(_result.msginfo));
			}
		}
	});
}

//预先制作出货单
function AddShip_Js() {
	myApp.confirm(_("确定要预先制作出货单吗？"),function() {
		//OrderIDs值组装 _orderIDs="232,324"
		var orderlistCb = $("#order .check_list_box span.selected"); //checked的
		var _orderIDs = "";
		for(var i = 0; i < orderlistCb.length; i++) {
			if(i == 0)
				_orderIDs += orderlistCb[i].lang;
			else
				_orderIDs += "," + orderlistCb[i].lang;
		}
		
		$.ajax({
			url: "/Team/AddShipOrderNew",
			type: "POST",
			data: "{'OrderIDs':'" + _orderIDs + "'}",
			contentType: "application/json; charset=utf-8",
			success: function(result) {
				var _result = eval('(' + result + ')'); //eval()解析单个json对象
				myApp.alert(_(_result.msginfo));
				$("#checkbox_check_all").removeClass("selected"); //清除全选
				$('.order-choose-detail span b').html(0);
				OrderSearch();
			}
		});
	});
}

//单个改价
function ReviseAnOrder_Js(me) {

	$(me).css("background-position", "-62px -148px"); //换笔头图片
	var ReviseOrder = {};
	ReviseOrder.OrderID = me.getAttribute("value");
	var Url;
	if(Type=="parcels"){
		ReviseOrder.GoodsType =2;
	}else if(Type=="rings"){
		ReviseOrder.GoodsType =3;
	}else if(Type=="gems"){
		ReviseOrder.GoodsType =4;
	}else if(Type=="emeralds"){
		ReviseOrder.GoodsType =5;
	}else if(Type=="golds"){
		ReviseOrder.GoodsType =6;
	}else if(Type== "inlaysettings"){
        ReviseOrder.GoodsType =7;
	}

	//订单信息
	$.ajax({
		url: "/Team/GetOrderNew",
		type: "POST", 
		data: JSON.stringify(ReviseOrder),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); 
			
			if(_result.msgcode == true){
				var  _result = _result.msginfo
				myApp.popup(".ReviseAnOrder_box");	
				//基本信息
				$("#_anorderid").val(_result.OrderID);
				$("#_salesRate").val(_result.SalesExchangerate);
				//_confirmPrice    _BEFPrice
				if(Type=="parcels"){
					$("#_confirmPrice").val(Math.round(_result.ConfirmRMB)); //人民币
					$("#_BEFPrice").val(Math.round(_result.ConfirmUSD));  //美金
				}else if(Type == "inlaysettings"){
                    var _resData=JSON.parse(_result.InventoryAttribute)
                    $("#form_material").val(_resData.Material);  //材质
                    $("#g_price").val(_resData.CustomerGoldPrice); //金价
                    $("#g_price").attr('data-val',_resData.CustomerGoldPrice);
                    $("#g_TotalWeight").val(_resData.TotalWeight); //总重
                    $("#g_NetGoldWeight").val(_resData.NetGoldWeight); //净重
                    $("#g_NetGoldWeight").attr("data-val",_resData.NetGoldWeight); //净重
                    $("#g_Wastage").val(_resData.CustomerWastage); //损耗
                    $("#g_Wastage").attr("data-val",_resData.CustomerWastage);
                    $("#g_SidePrice").val(_resData.CustomerSidePrice); //副石金额
                    $("#g_SidePrice").attr("data-val",_resData.CustomerSidePrice);
                    $("#g_LaborFee").val(_resData.CustomerLaborFee); //工费
                    $("#g_LaborFee").attr("data-val",_resData.CustomerLaborFee);
                    $("#g_SideLaborFee").val(_resData.CustomerSideLaborFee); //副石工费
                    $("#g_SideLaborFee").attr("data-val",_resData.CustomerSideLaborFee);
                    $("#g_SideNum").val(_resData.SideNum);//副石粒数
                    $("#g_SideNum").attr("data-val",_resData.SideNum);
                    $("#g_Insurance").val(_resData.CustomerInsurance); //保险费
                    $("#g_Insurance").attr("data-val",_resData.CustomerInsurance);
                    $("#_confirmPrice").val(formatRMBPrice(_result.ConfirmRMB)); //￥/Pcs
                    $("#_confirmPrice").attr('data-val',formatRMBPrice(_result.ConfirmRMB)); //￥/Pcs
					$("#discounts").text(_result.Discounts); //优惠
					$("#discounts").attr('data-val',_result.Discounts);
				}else{
					$("#_confirmPrice").val(Math.round(_result.ConfirmRMB));
					$("#_BEFPrice").val(Math.round(_result.ConfirmUSD));
				}
			}else{
				$(".ReviseAnOrder_box").hide();
				toast(_(_result.msginfo));
			}

			

		}
	});
}

//订单出货
function EditShip_Js(){
   myApp.popup(".EditShip_box");
}
//出货
function EditShip() {

	//OrderIDs值组装 _orderIDs="232,324"
	var orderlistCb = $("#order .check_list_box span.selected"); //checked的
	var _orderIDs = "";
	for(var i = 0; i < orderlistCb.length; i++) {
		if(i == 0)
			_orderIDs += orderlistCb[i].lang;
		else
			_orderIDs += "," + orderlistCb[i].lang;
	}
	
	$.ajax({
		url: "/Team/ShipOrdersNew",
		type: "POST", 
		data: "{'OrderIDs':'" + _orderIDs + "','ShipRemarks':'" + $("#_shipRemarks").val() + "'}",
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); 
			myApp.alert(_(_result.msginfo));
			if(_result.msgcode == true) {				
				myApp.closeModal(".EditShip_box");
				$("#check-total-price").html(0);
				OrderSearch(); //加载订单列表
			}
			
		}
	});
}

//计算差额
function ComputeXX() {
	var _am = $("#receivable").val();
	var _x = $("#amount").val();

	if(_am - _x > 0) {
		$("#_xx").val(_am - _x);
	} else {
		$("#_xx").val(0);
	}
}

//计算差额
function ComputeX() {
	var _am = $("#usdreceivable").val();
	var _x = $("#usdamount").val();

	if(_am - _x > 0) {
		$("#_usdxx").val(_am - _x);
	} else {
		$("#_usdxx").val(0);
	}
}

//确定申请充值 12-10
function ApplyFlow() {

	var requestFlow = {};

	requestFlow.CustomerID = $("#_custID").val(); //客户ID
	requestFlow.ApplyID = customerId;
	requestFlow.Remarks = $("#cremarks").val();
	requestFlow.Amount = $("#camount").val();
	requestFlow.ArrivalTime = $("#carrivalTime").val();
	requestFlow.Type = 1; //定金1（收入） 提现2（支出）
	requestFlow.Abstract = 2; //操作类型(摘要) 1.出货全款 2.定货款/尾款
	requestFlow.Currency = 1; //币种 1.人民币 2.美元
	requestFlow.Status = 0; //0待审核 1已审核 -1 已作废

	//requestFlow.Account =$('input:radio[name="Account"]:checked').val(); 
	requestFlow.Account = $('#_bankID1 input:radio[name="Account"]:checked').val(); //动态radio 12-21

	$.ajax({
		url: "/Team/AddFlow", 
		type: "POST",
		data: JSON.stringify(requestFlow),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象

			$(".Balance_box input[type=reset]").trigger("click"); //清空form数据 12-10

			if(_result.msgcode == true) {
				myApp.alert(_(_result.msginfo));
//				window.location.href = "/team/apply"; //申请 12-9
				//$(".delete_pop_box").hide();
			} else {
				myApp.alert(_(_result.msginfo)); //失败
				//$(".delete_pop_box").hide();
			}

		}
	});
}

//确定申请美金充值 01-18
function ApplyUSDFlow() {

	var requestUSDFlow = {};

	requestUSDFlow.CustomerID = $("#_cuID").val(); //客户ID
	requestUSDFlow.ApplyID = customerId;
	requestUSDFlow.Remarks = $("#cusdremarks").val();
	requestUSDFlow.Amount = $("#cusdamount").val();
	requestUSDFlow.ArrivalTime = $("#cusdarrivalTime").val();
	requestUSDFlow.Type = 1; //定金1（收入） 提现2（支出）
	requestUSDFlow.Abstract = 2; //操作类型(摘要) 1.出货全款 2.定货款/尾款
	requestUSDFlow.Currency = 2; //币种 1.人民币 2.美元
	requestUSDFlow.Status = 0; //0待审核 1已审核 -1 已作废

	//requestUSDFlow.Account =$('input:radio[name="Account"]:checked').val(); 
	requestUSDFlow.Account = $('#_usdbankID input:radio[name="Account"]:checked').val(); //动态radio 12-21

	$.ajax({
		url: "/Team/AddFlow",
		type: "POST", 
		data: JSON.stringify(requestUSDFlow),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象

			$(".USDBalance_box input[type=reset]").trigger("click"); //清空form数据 12-10

			if(_result.msgcode == true) {
				myApp.alert(_(_result.msginfo));
//				window.location.href = "/team/apply"; //申请 12-9
				//$(".delete_pop_box").hide();
			} else {
				myApp.alert(_(_result.msginfo)); //失败
				//$(".delete_pop_box").hide();
			}

		}
	});
}

//删除
function DelOrders_Js() {
	myApp.popup(".DelOrders_box");

	//仅管理员
	$(".btn_dis").attr("disabled", "disabled");
	if(RoleID == 1) {
		$(".btn_dis").removeAttr("disabled");
	}

}

//刷新
function Refresh() {
	window.location.reload(true); //刷新当前页面
}

//订单页码搜索
//首页
function firstp() {
	var lastp = $("#_pageCount").html();
	$(".page_num").html(1);
	OrderSearch();
}
//尾页
function lastp() {
	var lastp = $("#_pageCount").html();
	$(".page_num").html(lastp);
	OrderSearch();
}
//下一页
function next() {
	var num = $(".page_num").html();
	var totalPages = $("#_pageCount").html(); //总页数
	if(parseInt(num) < parseInt(totalPages)) {
		num++;
		$(".page_num").html(num);

		//加载订单
		OrderSearch();
	} else {}
}
//上一页
function prev() {
	var num = $(".page_num").html();
	if(num != 1) {
		num--;
		$(".page_num").html(num);
		OrderSearch();
	} else {}
}

//客户充值
function AddCharge() {

	var requestCharge = {};

	requestCharge.AmountOfMoney = $("#AmountOfMoney").val();
	requestCharge.AdddateTime = $("#AdddateTime").val();
	requestCharge.PaymentModel = $('input:radio[name="PaymentModel"]:checked').val(); //选项卡
	requestCharge.Remarks = $("#Remarks").val();
	requestCharge.OperationModel = $("#OperationModel option:checked").val(); //0 申请充值 1确认充值 -1 作废记账单
	requestCharge.customer_id = $("#_customerid").val(); //客户ID

	requestCharge.user_id = customerId; //团队ID  （审核人.直接充值时使用，申请充值时不使用）      

	$.ajax({
		url: "/Team/AddCharge", 
		type: "POST",
		data: JSON.stringify(requestCharge),
		contentType: "application/json; charset=utf-8",
		success: function(result) {
			var _result = eval('(' + result + ')'); //eval()解析单个json对象

			$(".ReCharge_box input[type=reset]").trigger("click"); //清空form数据 8-30 关键 一定要放最前面

			$(".ReCharge_box").hide(); //关闭客户充值框
			$(".addcharge_box").show(); //充值详情框显示 9-26

			$("#_add_result").html(_(_result['msginfo']));


		}
	});
}

//查看充值
function ViewCharge() {
	window.location.href = "/team/charge";
}

//继续充值
function choice() {
	$(".addcharge_box").hide(); //充值结果框隐藏            
	CustomerSearch(); //搜索客户8-28
}

//判断浏览器
function BrowserType() {
	var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
	var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器  
	var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器  
	var isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") >= -1 && !isIE; //判断是否IE的Edge浏览器  
	var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器  
	var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") == -1; //判断是否Safari浏览器  
	var isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("Safari") > -1; //判断Chrome浏览器  

	if(isIE) {
		var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
		reIE.test(userAgent);
		var fIEVersion = parseFloat(RegExp["$1"]);
		if(fIEVersion == 7 || fIEVersion == 8 || fIEVersion == 9) {
			return 0;
		}
		if(fIEVersion == 10 || fIEVersion == 11) {
			return 1;
		} else {
			return 0
		} //IE版本过低  
	} //isIE end  
	if(isFF) {
		return 2;
	}
	if(isOpera) {
		return 3;
	}
	if(isSafari) {
		return 4;
	}
	if(isChrome) {
		return 5;
	}
	if(isEdge) {
		return 6;
	}
}



//按钮弹框
//作废订单
function CancelOrders_Js() {
    myApp.popup(".CancelOrders_box");
}

//付款
function ReceiptOrders_Js() {


     //仅管理员1 和 财务2

        myApp.popup(".ReceiptOrders_box");
        //付款账户
        $.ajax({
            url: "/Team/GetBankList",
            type: "POST",
            data: "{'Status':'" + 1 + "','CheckResult':'" + 1 + "'}",
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                var _result = eval('(' + result + ')');
				$(".check_third").html($("#check-total-price").html());
				$(".check_four").html($("#check-total-price-usd").html());
                var options = "";
                options += '<option value="">'+_("选择账户")+'</option>';
                for (var i = 0; i < _result.length; i++) {
                    options += '<option value="' + _result[i].BankID + '"  >【' + _result[i].BankName + '】' + _result[i].BankBalance + '' + CurrencyFormat(_result[i].Currency) + '</option>';
                }
                $("#_receiptBankID").html("");
                $("#_receiptBankID").html(options);
            }
        });

}
//统包 采购和售价
function modify_boxsParcel(data){
	var str='';
    var status = data.OrderStatus;
    var data_parse = JSON.parse(data.InventoryAttribute);
    str="<div class='btn_box'>"
    if((status <4 && status > 0 && (menu_team_parcels_btn_order_price_btn || RoleID == 1))||(RoleID ==1&&status ==4) ){
        str+= "<span class='order_btn modify' title='修改售价' onclick='ReviseAnOrder_Js(this)' value='" +
            data.OrderID + "'>"+_("售价")+"</span>";
    }
    if((status <4 && status > 0 && (menu_team_parcels_btn_order_procurement_btn || RoleID == 1)) || (RoleID ==1&&status ==4) ){
        str+= "<span class='order_btn modify' lang='"+data_parse.Category+"' value='" + data.OrderID +
            "' title='采购订单' onclick='modify_box(this)'>"+_("采购")+"</span>";
    }
    str+="</div>";
    return str;
}

//操作按钮判断   "采购，售价"成品
function modify_boxsRing(data){
    var str='';
	var status = data.OrderStatus;
	var data_parse = JSON.parse(data.InventoryAttribute);
    str="<div class='btn_box'>";
    if((status <4 && status > 0 && (menu_team_rings_btn_order_price_btn || RoleID == 1))||(RoleID ==1&&status ==4) ){
        str+= "<span class='order_btn modify' title='修改售价' onclick='ReviseAnOrder_Js(this)' value='" +
            data.OrderID + "'>"+_("售价")+"</span>";
    }
    if((status <4 && status > 0 && (menu_team_rings_btn_order_procurement_btn || RoleID == 1)) || (RoleID ==1&&status ==4) ){
        str+= "<span class='order_btn modify' lang='"+data_parse.Category+"' value='" + data.OrderID +
            		"' title='采购订单' onclick='modify_box(this)'>"+_("采购")+"</span>";
	}
    str+="</div>";
    return str;
}

//操作按钮 采购 售价 彩宝
function modify_boxsGems(data){
    var str='';
    var status = data.OrderStatus;
    var data_parse = JSON.parse(data.InventoryAttribute);
    str="<div class='btn_box'>";
    if((status <4 && status > 0 && (menu_team_gems_btn_order_price_btn || RoleID == 1))||(RoleID ==1&&status ==4) ){
        str+= "<span class='order_btn modify' title='修改售价' onclick='ReviseAnOrder_Js(this)' value='" +
            data.OrderID + "'>"+_("售价")+"</span>";
    }
    if((status <4 && status > 0 && (menu_team_gems_btn_order_procurement_btn || RoleID == 1)) || (RoleID ==1&&status ==4) ){
        str+= "<span class='order_btn modify' lang='"+data_parse.Category+"' value='" + data.OrderID +
            "' title='采购订单' onclick='modify_box(this)'>"+_("采购")+"</span>";
    }
    str+="</div>";
    return str;
}

//操作空托
function modify_boxsInlaysettings(data){
    var str='';
    var status = data.OrderStatus;
    str="<div class='btn_box'>";
    if((status <4 && status > 0 && (menu_team_inlaysettings_btn_order_price_btn || RoleID == 1))||(RoleID ==1&&status ==4)  ){
        str+= "<span class='order_btn modify' title='修改售价' onclick='ReviseAnOrder_Js(this)' value='" +
            data.OrderID + "'>"+_("售价")+"</span>";
    }
    if((status <4 && status > 0 && (menu_team_inlaysettings_btn_order_procurement_btn || RoleID == 1)) || (RoleID ==1&&status ==4) ){
        str+= "<span class='order_btn modify' lang='1' value='" + data.OrderID +
            "' title='采购订单' onclick='modify_box(this)'>"+_("采购")+"</span>";
    }
    str+="</div>";
    return str;
}


//加载订单
function OrderSearch() {
    var self = this;
   //	myApp.showIndicator();//显示加载中
    if(PARAMS==null){
		var p={};
		p.OrderStatus="8";
		p.PageIndex="1";
		p.PageSize="200";
	}else{
		 var p = PARAMS.orderParams;//获取参数
	}
	$("#choose_orderstatus").text(UserOrderStatusFormat(p.OrderStatus));
    //获取排序
    var sort = $(".filter-box li i[data-sort-direct]");//获取排序框
    if (p && sort.length > 0 && sort.attr("data-sort-direct")) {//参数和排序长度均大于0,且存在data-sort-direct属性
        p["SortColumn"] = sort.attr("data-sort");//获取排序名称，退点或总价
        p["SortDirect"] = sort.attr("data-sort-direct");//获取排序类型，升序或降序
    }
    
	if(Type=="parcels"){
		p.GoodsType=2;
	}else if(Type=="rings"){
		p.GoodsType=3;
	}else if(Type=="gems"){
		p.GoodsType=4;
	}else if(Type=="emeralds"){
		p.GoodsType=5;
	}else if(Type=="golds"){
		p.GoodsType=6;
	}else if(Type="inlaysettings"){
        p.GoodsType=7;
	}
    var requestJson = JSON.stringify(p);
    $.ajax({
        url: "/Team/GetOrderNewList",
        type: "POST",
        data: requestJson,
        contentType: "application/json",
        success: function (result) {
			BindingOrder(result);//绑定数据
			var _result=JSON.parse(result);

            _result=_result.msginfo;
			var num=0;
			for(var i=0;i<_result.length;i++){
				var dataStatus=_result[i].OrderStatus;

				if(dataStatus===-1){
					num+=1
				}

			}
			//LoadOrderStatusNumber(num,requestOrder);//订单类型个数
            myApp.hideIndicator();//隐藏加载中
            if(APP){
        		YiYi_APP.refreshOrderNumber();//重新统计状态数量
        	}  
        }
    });
    searClearAll();
  }

function calMoney(){
    var chargingAmount=Number($("#_chargingAmount").val());
    if(chargingAmount>0){
        $("#remarks_inp").show();
        $("#arrivalTime_inp").show();
        $("#_remarks2").addClass("error");
        $("#_remarks2").prop("required",true);
        $("#_remarks2").val('');
    }else{
        $("#remarks_inp").hide();
        $("#arrivalTime_inp").hide();
        $("#_remarks2").removeClass("error");
        $("#_remarks2").prop("required",false);
        $("#_remarks2").val('');
    }
}


